export default {
  data() {
    return {
      // 上传图片
      imgPolicy: '',
      imgAuthorization: '',
      imgHost: '',
      idcardimgz: 'https://files.yzsheng.com/client/commodity/zhengmian@2x.png',
      idcardimgf: 'https://files.yzsheng.com/client/commodity/fanmian@2x.png',
      positiveIdentity: '', //身份正面
      oppositeIdentity: '', //身份反面
      biaoshi: true,
      tishizd: 'https://files.yzsheng.com/client/commodity/tishi@2x.png',
      guidePagess: false, //true隐藏  false显示
      carids: '', //暂存id
      zmsc: false,
      fmsc: false,
      dousc: false,
      idcarderroZm: false, //身份证上次错误提示
      idcarderroFm: false //身份证上次错误提示
    }
  },
  created() {
    // this.pageUrl()
  },
  onLoad(caridxix) {
    this.carids = caridxix.typeid
    console.log(this.carids)
    // this.CheckIDCardVerify() //判断身份证上传接口
    this.loadExecution() //调用页面
  },
  mounted() {
    this.getImageConfig()
  },
  methods: {
    /* // 判断身份证上传接口
		async CheckIDCardVerify() {
		  try {
		    const res = await this.$api.commodity.CheckIDCardVerify({})
		    if (res.code === 200) {
		      this.guidePagess = res.data
		      uni.setStorage({
		        key: 'idcards',
		        data: this.guidePagess,
		      })
		      this.loadExecution() //调用页面

		      this.$refs.uToast.show({
		        title: '认证成功',
		        type: 'success',
		        url: '/pages/user/index'
		      })
		    }
		  } catch (err) {}
		}, */
    loadExecution: function() {
      /**
			 * 获取本地存储中idcards的值
			 * 若存在，说明不是首次启动，直接进入首页；
			 * 若不存在，说明是首次启动，进入引导页；
			 */
      try {
        // 获取本地存储中idcards标识
        const value = uni.getStorageSync('idcards')
        console.log(value,'value')
        if (value) {
          // idcards=true直接跳转到首页
          if (this.carids === '110') {
            uni.navigateBack({})
          } else if (this.carids === 'withdrawal') {
            this.guidePagess = true
          } else {
            uni.redirectTo({
              url: '/pages_commodity/carPurchaseApplicationss/carPurchaseApplication?cartyid=' +
								this.carids
            })
          }
        } else {
          // idcards!=true显示引导页
          this.guidePagess = true
        }
      } catch (e) {
        // error
        uni.setStorage({
          key: 'idcards',
          data: true,
          success: function() {
            console.log('error时存储idcards')
          }
        })
        this.guidePagess = true
      }
      return
      if (this.carids === '110') {
        uni.navigateBack({})
      } else if (this.carids === 'withdrawal') {
        this.guidePagess = true
      } else {
        uni.redirectTo({
          url: '/pages_commodity/carPurchaseApplication/carPurchaseApplication?cartyid=' + this
            .carids
        })
      }
    },
    //身份证上传接口
    async IDCardVerify(type) {
      uni.showLoading({
        title: '加载中',
        mask: true
      })
      if (this.positiveIdentity === '') {
        this.$refs.uToast.show({
          title: '请上传身份证正面',
          type: 'warning',
          url: '/pages/user/index'
        })
        this.dousc = false
        uni.hideLoading()
        return false
      } else if (this.oppositeIdentity === '') {
        this.$refs.uToast.show({
          title: '请上传身份证背面',
          type: 'warning',
          url: '/pages/user/index'
        })
        this.dousc = false
        uni.hideLoading()
        return false
      }
      try {
        const res = await this.$api.commodity.IDCardVerify({
          frontImg: this.positiveIdentity,
          backImg: this.oppositeIdentity
        })
        if (res.code === 200) {
          uni.hideLoading()
          if (this.carids === '110') {
            uni.navigateBack({})
          } else if (this.carids === 'withdrawal') {
            this.pageUrl()
          } else {
            uni.redirectTo({
              url: '/pages_commodity/carPurchaseApplication/carPurchaseApplication?cartyid=' +
								this.carids
            })
          }
        } else {
          if (res.msg === '请上传正确的身份证正面照') {
            this.idcarderroZm = true
          } else if (res.msg === '请上传正确的身份证背面照') {
            this.idcarderroFm = true
          }
        }
      } catch (err) {}
    },
    tijiao() {
      if (this.positiveIdentity === '') {
        this.$refs.uToast.show({
          title: '请上传身份证正面',
          type: 'warning',
          url: '/pages/user/index'
        })
        this.dousc = false
        return false
      } else if (this.oppositeIdentity === '') {
        this.$refs.uToast.show({
          title: '请上传身份证背面',
          type: 'warning',
          url: '/pages/user/index'
        })
        this.dousc = false
        return false
      }
    },
    //获取图片上传配置信息
    async getImageConfig() {
      try {
        const res = await this.$api.user.getImageConfig()
        this.imgAuthorization = res.data.auth
        this.imgPolicy = res.data.policy
        this.imgHost = res.data.host
      } catch (e) {
        //TODO handle the exception
      }
    },
    // 身份证正面
    UploadIDcardImgz() {
      this.uploadImage()
      this.biaoshi = true
    },
    // 身份证反面
    UploadIDcardImgf() {
      this.uploadImage()
      this.biaoshi = false
    },
    //选择图片
    uploadImage() {
      uni.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        success: result => {
          uni.showLoading({
            title: '图片上传中~',
          })
          this.$api.files.uploadImg({
            filePath: result.tempFilePaths[0], // 图片流
          }).then(res => {
            console.log(res)
            var urls = res.baseUrl + res.url
            this.FanHUIimgs(urls)

            uni.hideLoading()
          })
        },
        error: function(e) {}
      })
    },
    //上传图片赋值
    FanHUIimgs(res) {
      if (this.biaoshi) {
        this.idcardimgz = res
        this.positiveIdentity = res
        this.idcarderroZm = false
      } else {
        this.idcardimgf = res
        this.oppositeIdentity = res
        this.idcarderroFm = false
      }
      if (this.positiveIdentity !== '' && this.oppositeIdentity !== '') {
        this.dousc = true
      }
    },
    //查看用户协议
    look() {
      uni.navigateTo({
        url: '/pages_logins/userAgreementPopup/userAgreementPopup'
      })
    },

    //跳转通联
    async pageUrl() {
      uni.showLoading()
      try{
        uni.hideLoading()
        const res = await this.$api.fundModule.signContract()
        console.log(res)
        uni.navigateTo({
          url: '/pages_fundModule/authorization/authorization?link=' + encodeURIComponent(res
            .data.uRl)+'&type=0'
        })
      }catch(e){
        uni.hideLoading()
      }

      /* uni.request({
        url: 'http://192.168.0.125:89/api/common/core/YST/SignContractURL',
        method: 'POST',
        header: {
          'content-type': 'application/json; charset=utf-8',
          'Auth': uni.getStorageSync('token')
        },
        success: res => {
          uni.hideLoading()
          console.log(res)
          uni.navigateTo({
            url: '/pages_fundModule/authorization/authorization?link=' + encodeURIComponent(res
              .data.data.uRl)+'&type=0'
          })
        },
        fail: err => {
          uni.hideLoading()
          console.log(err)
        }
      }) */
    },
  }
}
